package com.dmai.capacity.platform.common.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

import com.dmai.capacity.platform.common.constant.CodeEnum;


@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseEntity<T> implements Serializable {

	private Integer code;
	private String msg;
	private T data;

	public static <T> ResponseEntity<T> succeed(String msg) {
		return of(CodeEnum.SUCCESS.getCode(), msg, null);
	}

	public static <T> ResponseEntity<T> succeed(T data, String msg) {
		return of(CodeEnum.SUCCESS.getCode(), msg, data);
	}

	public static <T> ResponseEntity<T> succeed(T data) {
		return of(CodeEnum.SUCCESS.getCode(), "", data);
	}

	public static <T> ResponseEntity<T> of(Integer code, String msg, T data) {
		return new ResponseEntity<>(code, msg, data);
	}

	public static <T> ResponseEntity<T> failed(String msg) {
		return of(CodeEnum.ERROR.getCode(), msg, null);
	}

	public static <T> ResponseEntity<T> failed(T data, String msg) {
		return of(CodeEnum.ERROR.getCode(), msg, data);
	}
	
	public static <T> ResponseEntity<T> succeedWith(T data, Integer status, String msg) {
		return new ResponseEntity<T>(status, msg , data);
	}

	public static <T> ResponseEntity<T> failedWith(T data, Integer status, String msg) {
        return new ResponseEntity<T>(status  , msg , data);
    }
	
}
